import pymysql

def main():
    conn = pymysql.connect(
        host='localhost',
        port=3306,
        user='root',
        password='123456',
        db='hrs',
        charset='utf8mb4'

    )
    try:
        with conn.cursor() as cursor:
            result = cursor.execute(
                'insert into tb_dept values (90,"销售二部","重庆")')
            if result == 1:
                print('添加成功')

            conn.commit()

    finally:
        conn.close()


    print(conn)


if __name__ == '__main__':
    main()